package com.blog.zs.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.blog.zs.Service.ArticleService;
import com.blog.zs.model.Article;
import com.blog.zs.tool.ArticleContent;
import com.blog.zs.tool.Pagination;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ArticleAction extends ActionSupport{

	private int page;
    private Pagination pagination;
    List<Integer> list = new ArrayList<Integer>();
	private Integer id;
	private String author;
	private String title;
	private String content;
	private String type;
	private Date createtime;
	private ArticleService articleService;
	private Article article;
	private ArticleContent acontent;
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public Pagination getPagination() {
		return pagination;
	}
	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}
	public List<Integer> getList() {
		return list;
	}
	public void setList(List<Integer> list) {
		this.list = list;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Date getCreatetime() {
		return createtime;
	}
	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}
	public ArticleService getArticleService() {
		return articleService;
	}
	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}
	public Article getArticle() {
		return article;
	}
	public void setArticle(Article article) {
		this.article = article;
	}
	public ArticleContent getAcontent() {
		return acontent;
	}
	public void setAcontent(ArticleContent acontent) {
		this.acontent = acontent;
	}
	public String saveArticle() throws Exception {
	    Article article = new Article();
	    article.setAuthor("GenXL");
	    article.setTitle(title);
	    article.setType(type);
	    article.setCreatetime(new Date());
		articleService.saveBlog(article, content);
	    return SUCCESS;
	  }
	
	public String listArticle() throws Exception {
		this.pagination = articleService.queryForPage(5, page);
		for(int i=1;i<=pagination.getTotalPage();i++){
			this.list.add(1);
			}
		return SUCCESS;
	  }
	
	public String getArticleContent() throws Exception {
		acontent = articleService.getContentById(id);
		return SUCCESS;
	  }
}
